﻿using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace Athena.RabbitMQ.Performance.Test
{
    using Implementations;
    class Program
    {

        static Task<int> TaskCompletionSourceTest()
        {



            var taskCompletionSource = new TaskCompletionSource<int>();
            Task.Run(async () =>
            {
                await Task.Delay(1000);
                Console.WriteLine("delay 1000 now");
                taskCompletionSource.SetResult(1);
            });
            return taskCompletionSource.Task;
        }

        static void RabbitMQModelTest()
        {
            var rabbitMQConnection = new RabbitMQConnection();

            var connection = rabbitMQConnection.CreateConnection(new RabbitMQConnectionConfigure()
            {
                HostName = "192.168.1.142",
                Password = "y4yh69t",
                UserName = "ucity_test",
                VirtualHost = "qrcode"
            });
            var stopWatch = new Stopwatch();
            stopWatch.Start();
            int id = 0;
            while (id < 1000)
            {
                var channel = connection.CreateModel();
                channel.Close();
                id++;
            }
            Console.WriteLine("exec:" + stopWatch.ElapsedMilliseconds + " ms");
            rabbitMQConnection.Dispose();
            stopWatch.Stop();

            Console.ReadKey();
        }

        public static void ShowThreadNo()
        {
            for (int i = 0; i < 1000; i++)
            {
                Task.Factory.StartNew(() =>
                {
                    Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
                });
            }
            Console.ReadKey();
        }

        static void Main(string[] args)
        {
            //{
            //    Stopwatch stopwatch = new Stopwatch();
            //    //var task = TaskCompletionSourceTest();
            //    stopwatch.Start();
            //    //Console.WriteLine(task.Result);

            //    int id = 0;
            //    while (id < 100000)
            //    {
            //        var tid = Thread.CurrentThread.ManagedThreadId;
            //        id++;
            //    }


            //    stopwatch.Stop();
            //    Console.Write($"exec {stopwatch.ElapsedMilliseconds}");
            //    Console.ReadKey();
            //RabbitMQModelTest();
            ShowThreadNo();
        }
    }
}
